Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid the use/creation of real databases in the UTs. #570

Merged

Conversation

Nicogp
Copy link
Member

@Nicogp Nicogp commented Feb 3, 2025

Description

This PR adds the necessary changes to avoid the use and/or creation of the agent_info.db database in the UTs.

Proposed Changes

The Persistence interface is used to declare a mock class(MockPersistence) that implements this interface in order to mock the methods used by AgentInfoPersistance

The changes include:

  • Creation of class MockPersistence
  • Changes in the constructor of AgentInfoPersistance to be able to inject the object of the MockPersistence class.
  • Creating UTs for AgentInfoPersistance
  • Changes in the constructor of AgentInfo, AgentRegistration and Agent to be able to inject an object of the AgentInfoPersistance class created with the MockPersistence object injection.
  • Correction of AgentInfo, AgentRegistration and Agent UTs

Results and Evidence

Running of the Agent:

Agent Registration:

ls /var/lib/wazuh-agent/

./wazuh-agent --register-agent --password wazuh --user wazuh --url https://192.168.0.177:55000
Starting wazuh-agent registration
wazuh-agent registered

ls /var/lib/wazuh-agent/
agent_info.db

sqlite3 /var/lib/wazuh-agent/agent_info.db "select * from agent_info;"
nico-VirtualBox|MA9quV4YbKVe6t02BpNald22hXZy7E6z|43ed9670-06ac-41d5-b1d2-72273b6fb3e8

Agent Run:

./wazuh-agent 
[2025-02-11 11:59:00.222] [wazuh-agent] [info] [INFO] [process_options_unix.cpp:24] [StartAgent] Starting wazuh-agent
[2025-02-11 11:59:00.722] [wazuh-agent] [info] [INFO] [communicator.cpp:113] [SendAuthenticationRequest] Successfully authenticated with the manager.
[2025-02-11 11:59:00.769] [wazuh-agent] [info] [INFO] [inventory.cpp:19] [Start] Inventory module started.
[2025-02-11 11:59:00.777] [wazuh-agent] [info] [INFO] [logcollector.cpp:28] [Start] Logcollector module is disabled.
[2025-02-11 11:59:00.808] [wazuh-agent] [info] [INFO] [inventoryImp.cpp:991] [SyncLoop] Module started.
[2025-02-11 12:01:01.316] [wazuh-agent] [info] [INFO] [inventoryImp.cpp:974] [Scan] Starting evaluation.
[2025-02-11 12:01:36.321] [wazuh-agent] [info] [INFO] [inventoryImp.cpp:986] [Scan] Evaluation finished.

AgentInfoPersistance Test:

ls
agent_info_persistance_test  agent_info_test  CMakeFiles  cmake_install.cmake  CTestTestfile.cmake  Makefile
nico@nico-VirtualBox:~/wazuh-agent/build/agent/agent_info/tests$ ./agent_info_persistance_test 
[==========] Running 32 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 32 tests from AgentInfoPersistanceTest
[ RUN      ] AgentInfoPersistanceTest.TestConstruction
[       OK ] AgentInfoPersistanceTest.TestConstruction (3 ms)
[ RUN      ] AgentInfoPersistanceTest.TestGetNameValue
[       OK ] AgentInfoPersistanceTest.TestGetNameValue (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestGetNameNotValue
[       OK ] AgentInfoPersistanceTest.TestGetNameNotValue (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestGetNameCatch
[2025-02-11 12:08:23.524] [error] [ERROR] [agent_info_persistance.cpp:168] [GetAgentInfoValue] Error fetching name: Error Select.
[       OK ] AgentInfoPersistanceTest.TestGetNameCatch (435 ms)
[ RUN      ] AgentInfoPersistanceTest.TestGetKeyValue
[       OK ] AgentInfoPersistanceTest.TestGetKeyValue (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestGetKeyNotValue
[       OK ] AgentInfoPersistanceTest.TestGetKeyNotValue (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestGetKeyCatch
[2025-02-11 12:08:23.527] [error] [ERROR] [agent_info_persistance.cpp:168] [GetAgentInfoValue] Error fetching key: Error Select.
[       OK ] AgentInfoPersistanceTest.TestGetKeyCatch (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestGetUUIDValue
[       OK ] AgentInfoPersistanceTest.TestGetUUIDValue (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestGetUUIDNotValue
[       OK ] AgentInfoPersistanceTest.TestGetUUIDNotValue (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestGetUUIDCatch
[2025-02-11 12:08:23.527] [error] [ERROR] [agent_info_persistance.cpp:168] [GetAgentInfoValue] Error fetching uuid: Error Select.
[       OK ] AgentInfoPersistanceTest.TestGetUUIDCatch (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestGetGroupsValue
[       OK ] AgentInfoPersistanceTest.TestGetGroupsValue (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestGetGroupsNotValue
[       OK ] AgentInfoPersistanceTest.TestGetGroupsNotValue (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestGetGroupsCatch
[2025-02-11 12:08:23.527] [error] [ERROR] [agent_info_persistance.cpp:208] [GetGroups] Error getting agent group list: Error Select.
[       OK ] AgentInfoPersistanceTest.TestGetGroupsCatch (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestSetName
[       OK ] AgentInfoPersistanceTest.TestSetName (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestSetNameCatch
[2025-02-11 12:08:23.527] [error] [ERROR] [agent_info_persistance.cpp:146] [SetAgentInfoValue] Error updating name: Error Update.
[       OK ] AgentInfoPersistanceTest.TestSetNameCatch (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestSetKey
[       OK ] AgentInfoPersistanceTest.TestSetKey (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestSetKeyCatch
[2025-02-11 12:08:23.527] [error] [ERROR] [agent_info_persistance.cpp:146] [SetAgentInfoValue] Error updating key: Error Update.
[       OK ] AgentInfoPersistanceTest.TestSetKeyCatch (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestSetUUID
[       OK ] AgentInfoPersistanceTest.TestSetUUID (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestSetUUIDCatch
[2025-02-11 12:08:23.527] [error] [ERROR] [agent_info_persistance.cpp:146] [SetAgentInfoValue] Error updating uuid: Error Update.
[       OK ] AgentInfoPersistanceTest.TestSetUUIDCatch (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestSetGroupsSuccess
[       OK ] AgentInfoPersistanceTest.TestSetGroupsSuccess (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestSetGroupsBeginTransactionFails
[2025-02-11 12:08:23.541] [error] [ERROR] [agent_info_persistance.cpp:240] [SetGroups] Failed to begin transaction: Error BeginTransaction.
[       OK ] AgentInfoPersistanceTest.TestSetGroupsBeginTransactionFails (19 ms)
[ RUN      ] AgentInfoPersistanceTest.TestSetGroupsRemoveFails
[2025-02-11 12:08:23.547] [error] [ERROR] [agent_info_persistance.cpp:258] [SetGroups] Error inserting group: Error Remove.
[       OK ] AgentInfoPersistanceTest.TestSetGroupsRemoveFails (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestSetGroupsInsertFails1
[2025-02-11 12:08:23.547] [error] [ERROR] [agent_info_persistance.cpp:258] [SetGroups] Error inserting group: Error Insert.
[       OK ] AgentInfoPersistanceTest.TestSetGroupsInsertFails1 (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestSetGroupsInsertFails2
[2025-02-11 12:08:23.547] [error] [ERROR] [agent_info_persistance.cpp:258] [SetGroups] Error inserting group: Error Insert.
[       OK ] AgentInfoPersistanceTest.TestSetGroupsInsertFails2 (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestSetGroupsCommitFails
[2025-02-11 12:08:23.547] [error] [ERROR] [agent_info_persistance.cpp:258] [SetGroups] Error inserting group: Error Commit.
[       OK ] AgentInfoPersistanceTest.TestSetGroupsCommitFails (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestSetGroupsRollbackFails
[2025-02-11 12:08:23.547] [error] [ERROR] [agent_info_persistance.cpp:258] [SetGroups] Error inserting group: Error Commit.
[2025-02-11 12:08:23.547] [error] [ERROR] [agent_info_persistance.cpp:266] [SetGroups] Rollback failed: Error Rollback.
[       OK ] AgentInfoPersistanceTest.TestSetGroupsRollbackFails (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestResetToDefaultSuccess
[       OK ] AgentInfoPersistanceTest.TestResetToDefaultSuccess (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestResetToDefaultDropTableAgentInfoFails
[2025-02-11 12:08:23.547] [error] [ERROR] [agent_info_persistance.cpp:287] [ResetToDefault] Error resetting to default values: Error DropTable.
[       OK ] AgentInfoPersistanceTest.TestResetToDefaultDropTableAgentInfoFails (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestResetToDefaultDropTableAgentGroupFails
[2025-02-11 12:08:23.547] [error] [ERROR] [agent_info_persistance.cpp:287] [ResetToDefault] Error resetting to default values: Error DropTable.
[       OK ] AgentInfoPersistanceTest.TestResetToDefaultDropTableAgentGroupFails (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestResetToDefaultCreateAgentInfoTableFails
[2025-02-11 12:08:23.547] [error] [ERROR] [agent_info_persistance.cpp:92] [CreateAgentInfoTable] Error creating table: Error CreateAgentInfoTable.
[2025-02-11 12:08:23.547] [error] [ERROR] [agent_info_persistance.cpp:287] [ResetToDefault] Error resetting to default values: Error CreateAgentInfoTable.
[       OK ] AgentInfoPersistanceTest.TestResetToDefaultCreateAgentInfoTableFails (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestResetToDefaultCreateAgentGroupTableFails
[2025-02-11 12:08:23.547] [error] [ERROR] [agent_info_persistance.cpp:109] [CreateAgentGroupTable] Error creating table: Error CreateAgentGroupTable.
[2025-02-11 12:08:23.547] [error] [ERROR] [agent_info_persistance.cpp:287] [ResetToDefault] Error resetting to default values: Error CreateAgentGroupTable.
[       OK ] AgentInfoPersistanceTest.TestResetToDefaultCreateAgentGroupTableFails (0 ms)
[ RUN      ] AgentInfoPersistanceTest.TestResetToDefaultInsertFails
[2025-02-11 12:08:23.547] [error] [ERROR] [agent_info_persistance.cpp:131] [InsertDefaultAgentInfo] Error inserting default agent info: Error Insert.
[2025-02-11 12:08:23.547] [error] [ERROR] [agent_info_persistance.cpp:287] [ResetToDefault] Error resetting to default values: Error Insert.
[       OK ] AgentInfoPersistanceTest.TestResetToDefaultInsertFails (0 ms)
[----------] 32 tests from AgentInfoPersistanceTest (463 ms total)

[----------] Global test environment tear-down
[==========] 32 tests from 1 test suite ran. (465 ms total)
[  PASSED  ] 32 tests.
nico@nico-VirtualBox:~/wazuh-agent/build/agent/agent_info/tests$ ls
agent_info_persistance_test  agent_info_test  CMakeFiles  cmake_install.cmake  CTestTestfile.cmake  Makefile

AgentInfo Test:

ls
agent_info_persistance_test  agent_info_test  CMakeFiles  cmake_install.cmake  CTestTestfile.cmake  Makefile
nico@nico-VirtualBox:~/wazuh-agent/build/agent/agent_info/tests$ ./agent_info_test 
[==========] Running 13 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 13 tests from AgentInfoTest
[ RUN      ] AgentInfoTest.TestDefaultConstructorDefaultValues
[       OK ] AgentInfoTest.TestDefaultConstructorDefaultValues (62 ms)
[ RUN      ] AgentInfoTest.TestSetName
[       OK ] AgentInfoTest.TestSetName (0 ms)
[ RUN      ] AgentInfoTest.TestSetKey
[       OK ] AgentInfoTest.TestSetKey (0 ms)
[ RUN      ] AgentInfoTest.TestSetBadKey
[       OK ] AgentInfoTest.TestSetBadKey (0 ms)
[ RUN      ] AgentInfoTest.TestSetEmptyKey
[       OK ] AgentInfoTest.TestSetEmptyKey (0 ms)
[ RUN      ] AgentInfoTest.TestSetUUID
[       OK ] AgentInfoTest.TestSetUUID (7 ms)
[ RUN      ] AgentInfoTest.TestSetGroups
[       OK ] AgentInfoTest.TestSetGroups (0 ms)
[ RUN      ] AgentInfoTest.TestSaveGroups
[       OK ] AgentInfoTest.TestSaveGroups (52 ms)
[ RUN      ] AgentInfoTest.TestSave
[       OK ] AgentInfoTest.TestSave (1 ms)
[ RUN      ] AgentInfoTest.TestLoadMetadataInfoNoSysInfo
[       OK ] AgentInfoTest.TestLoadMetadataInfoNoSysInfo (0 ms)
[ RUN      ] AgentInfoTest.TestLoadMetadataInfoRegistration
[       OK ] AgentInfoTest.TestLoadMetadataInfoRegistration (0 ms)
[ RUN      ] AgentInfoTest.TestLoadMetadataInfoConnected
[       OK ] AgentInfoTest.TestLoadMetadataInfoConnected (4 ms)
[ RUN      ] AgentInfoTest.TestLoadHeaderInfo
[       OK ] AgentInfoTest.TestLoadHeaderInfo (0 ms)
[----------] 13 tests from AgentInfoTest (152 ms total)

[----------] Global test environment tear-down
[==========] 13 tests from 1 test suite ran. (152 ms total)
[  PASSED  ] 13 tests.
nico@nico-VirtualBox:~/wazuh-agent/build/agent/agent_info/tests$ ls
agent_info_persistance_test  agent_info_test  CMakeFiles  cmake_install.cmake  CTestTestfile.cmake  Makefile

AgentRegistration Test:

ls
agent_registration_test  agent_test  CMakeFiles  cmake_install.cmake  CTestTestfile.cmake  instance_handler_test  Makefile  message_queue_utils_test  signal_handler_test
nico@nico-VirtualBox:~/wazuh-agent/build/agent/tests$ ./agent_registration_test 
[==========] Running 8 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 8 tests from RegisterTest
[ RUN      ] RegisterTest.RegistrationTestSuccess
[       OK ] RegisterTest.RegistrationTestSuccess (163 ms)
[ RUN      ] RegisterTest.RegistrationFailsIfAuthenticationFails
Error authenticating: 401.
Failed to authenticate with the manager
[       OK ] RegisterTest.RegistrationFailsIfAuthenticationFails (12 ms)
[ RUN      ] RegisterTest.RegistrationFailsIfServerResponseIsNotOk
Registration error: 400.
[       OK ] RegisterTest.RegistrationFailsIfServerResponseIsNotOk (34 ms)
[ RUN      ] RegisterTest.RegisteringWithoutAKeyGeneratesOneAutomatically
[       OK ] RegisterTest.RegisteringWithoutAKeyGeneratesOneAutomatically (27 ms)
[ RUN      ] RegisterTest.RegistrationTestFailWithBadKey
[       OK ] RegisterTest.RegistrationTestFailWithBadKey (179 ms)
[ RUN      ] RegisterTest.RegistrationTestFailWithHttpClientError
[       OK ] RegisterTest.RegistrationTestFailWithHttpClientError (0 ms)
[ RUN      ] RegisterTest.AuthenticateWithUserPassword_Success
[       OK ] RegisterTest.AuthenticateWithUserPassword_Success (14 ms)
[ RUN      ] RegisterTest.AuthenticateWithUserPassword_Failure
Error authenticating: 401.
[       OK ] RegisterTest.AuthenticateWithUserPassword_Failure (3 ms)
[----------] 8 tests from RegisterTest (448 ms total)

[----------] Global test environment tear-down
[==========] 8 tests from 1 test suite ran. (463 ms total)
[  PASSED  ] 8 tests.
nico@nico-VirtualBox:~/wazuh-agent/build/agent/tests$ ls
agent_registration_test  agent_test  CMakeFiles  cmake_install.cmake  CTestTestfile.cmake  instance_handler_test  Makefile  message_queue_utils_test  signal_handler_test

Agent Test:

ls
agent_registration_test  agent_test  CMakeFiles  cmake_install.cmake  CTestTestfile.cmake  instance_handler_test  Makefile  message_queue_utils_test  signal_handler_test
nico@nico-VirtualBox:~/wazuh-agent/build/agent/tests$ ./agent_test 
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from AgentTests
[ RUN      ] AgentTests.AgentStopsWhenSignalReceived
[2025-02-11 12:13:25.481] [warning] [WARN] [communicator.cpp:183] [AuthenticateWithUuidAndKey] Error: 401.
[2025-02-11 12:13:25.481] [warning] [WARN] [communicator.cpp:117] [SendAuthenticationRequest] Failed to authenticate with the manager. Retrying in 30 seconds.
[2025-02-11 12:13:25.481] [warning] [WARN] [communicator.cpp:183] [AuthenticateWithUuidAndKey] Error: 401.
[2025-02-11 12:13:25.481] [warning] [WARN] [communicator.cpp:117] [SendAuthenticationRequest] Failed to authenticate with the manager. Retrying in 30 seconds.
[2025-02-11 12:13:25.640] [info] [INFO] [inventory.cpp:14] [Start] Inventory module is disabled.
[2025-02-11 12:13:25.643] [info] [INFO] [logcollector.cpp:28] [Start] Logcollector module is disabled.
[2025-02-11 12:13:25.665] [info] [INFO] [inventory.cpp:78] [Stop] Inventory module stopping...
[2025-02-11 12:13:25.671] [info] [INFO] [logcollector.cpp:100] [Stop] Logcollector module stopped.
[       OK ] AgentTests.AgentStopsWhenSignalReceived (4117 ms)
[----------] 1 test from AgentTests (4168 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (4196 ms total)
[  PASSED  ] 1 test.
nico@nico-VirtualBox:~/wazuh-agent/build/agent/tests$ ls
agent_registration_test  agent_test  CMakeFiles  cmake_install.cmake  CTestTestfile.cmake  instance_handler_test  Makefile  message_queue_utils_test  signal_handler_test
nico@nico-VirtualBox:~/wazuh-agent/build/agent/tests$ ls /tmp/
1e150c02-4c15-455d-aad5-7a608e036ad4       systemd-private-4d485f928d634310b93957c146f05974-ModemManager.service-IggciV
{256080BF-6BD4-420A-9F9F-C1D17F5713D5}     systemd-private-4d485f928d634310b93957c146f05974-systemd-logind.service-75z9fh
code-52fa87d6-21d7-4b18-871f-ab9a70dbe55d  systemd-private-4d485f928d634310b93957c146f05974-systemd-oomd.service-oqFjEI
command_store.db                           systemd-private-4d485f928d634310b93957c146f05974-systemd-resolved.service-k3aCqp
local.db                                   systemd-private-4d485f928d634310b93957c146f05974-upower.service-V080S4
local.db-journal                           unleash-backup-codeium-extension.json
queue.db                                   unleash-repo-schema-v1-codeium-language-server.json
snap-private-tmp                           VMwareDnD

As you can see, the agent_info.db database has not been created. The use of the other dbs in the UTs will be corrected in another issue.

Artifacts Affected

Executable files, all platforms.

Configuration Changes

None

Documentation Updates

None

Tests Introduced

Added:

  • AgentInfoPersistanceTest

Fixed:

  • AgentInfoTests
  • RegisterTest
  • AgentTests

Review Checklist

  • Code changes reviewed
  • Relevant evidence provided
  • Tests cover the new functionality
  • Developer documentation reflects the changes
  • Meets requirements and/or definition of done
  • No unresolved dependencies with other issues

@Nicogp Nicogp linked an issue Feb 3, 2025 that may be closed by this pull request
8 tasks
@Nicogp Nicogp force-pushed the enhancement/518-refactor-tests-to-mock-database-access branch 5 times, most recently from e734d9b to fe80020 Compare February 5, 2025 19:12
@Nicogp Nicogp force-pushed the enhancement/518-refactor-tests-to-mock-database-access branch 6 times, most recently from db233e0 to aa8aa7f Compare February 10, 2025 11:48
@Nicogp Nicogp removed a link to an issue Feb 10, 2025
8 tasks
@Nicogp Nicogp linked an issue Feb 10, 2025 that may be closed by this pull request
4 tasks
@Nicogp Nicogp force-pushed the enhancement/518-refactor-tests-to-mock-database-access branch from aa8aa7f to f73d423 Compare February 10, 2025 14:53
Copy link
Member

@jr0me jr0me left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we are doing the correct thing here by testing AgentInfo and AgentInfoRegistration with a mocked persistence class. The specific of the persistence implementation should be a detail visible only to AgentInfoPersistence, who uses it. In some of these tests we are actually testing the certain Persistence functions are being called, which I believe should be beyond the concerns of AgentInfo and AgentInfoRegistration. Maybe it would be more correct to test AgentInfo with a mocked AgentInfoPersistence, and to test AgentInfoRegistration with a mocked AgentInfo? Perhaps you already evaluated this, let me know what you think.

… AgentInfo object. The Agent UTs has also been fixed.
@Nicogp Nicogp force-pushed the enhancement/518-refactor-tests-to-mock-database-access branch from 4b26e04 to 513c83f Compare February 11, 2025 12:13
@Nicogp Nicogp force-pushed the enhancement/518-refactor-tests-to-mock-database-access branch from 513c83f to 150e1e1 Compare February 11, 2025 13:02
@Nicogp Nicogp marked this pull request as ready for review February 11, 2025 15:20
Copy link
Contributor

@aritosteles aritosteles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check all ocurrences of "persistance" and change it to "persistence" to keep some consistency

src/agent/agent_info/include/agent_info.hpp Show resolved Hide resolved
target_link_libraries(agent_info_test PRIVATE AgentInfo Persistence GTest::gtest)
target_include_directories(agent_info_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../src
${CMAKE_CURRENT_SOURCE_DIR}/../../persistence/tests/mocks)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for the future: we need to do this also with tests that use the http client mock.

@aritosteles aritosteles self-requested a review February 11, 2025 21:10
Copy link
Member

@jr0me jr0me left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Nicogp
Copy link
Member Author

Nicogp commented Feb 11, 2025

Hi @jr0me, I have created another issue to work on this.

I'm wondering if we are doing the correct thing here by testing AgentInfo and AgentInfoRegistration with a mocked persistence class. The specific of the persistence implementation should be a detail visible only to AgentInfoPersistence, who uses it. In some of these tests we are actually testing the certain Persistence functions are being called, which I believe should be beyond the concerns of AgentInfo and AgentInfoRegistration. Maybe it would be more correct to test AgentInfo with a mocked AgentInfoPersistence, and to test AgentInfoRegistration with a mocked AgentInfo? Perhaps you already evaluated this, let me know what you think.

@TomasTurina TomasTurina merged commit 19719ce into main Feb 11, 2025
5 checks passed
@TomasTurina TomasTurina deleted the enhancement/518-refactor-tests-to-mock-database-access branch February 11, 2025 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor the tests to mock access to the agent_info.db database.
4 participants